package com.ruoyi.common.utils;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTHeader;
import cn.hutool.jwt.JWTUtil;

import java.util.HashMap;
import java.util.Map;

public class JwtUtils {

    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>() {
            private static final long serialVersionUID = 1L;
            {
                put("uid", Integer.parseInt("123"));
                put("expire_time", System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 15);
            }
        };
//        String token = JWTUtil.createToken(map, "1234".getBytes());
        String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1fdGltZSI6MTcxMDkyMjM4NjIwMSwiYXBwaWQiOiJuc2t1YWlsYXdlYm1hbmFnZSJ9._Y8wQqWESV25rkKUz_znogoKEcOfcGMyIjRr66qC4xo";
        System.out.println("token = " + token);

        final JWT jwt = JWTUtil.parseToken(token);
        jwt.getHeader(JWTHeader.TYPE);
        String appid = jwt.getPayload("appid").toString();
        System.out.println("appid = " + appid);
        boolean verify = JWTUtil.verify(token, "lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI".getBytes());
        System.out.println("verify = " + verify);
    }
}
